package com.example.myapplication;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

public class SPSaveQQ {
    //1、保存
    /*
         SharedPreferences sp = getSharedPreferences("data",MODE_PRIVATE);
     SharedPreferences.Editor editor = sp.edit();
     editor.putString("name", "传智播客");
     editor.putInt("age", 8);
     editor.commit();

     */

    public static boolean saveUserInfo(Context context,String name,String password){
        SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString("n",name);
        editor.putString("p",password);
        editor.commit();
        return true;
    }
    //2、读取
    public static Map<String,String> getUserInfo(Context context){
        SharedPreferences sp=context.getSharedPreferences("data",Context.MODE_PRIVATE);
        String name=sp.getString("n","");
        String password=sp.getString("p","");
        Map<String,String> map= new HashMap<String, String>();
        map.put("username",name);
        map.put("userpassword",password);
        return map;
    }
}
